home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / value.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  14.6 KB  |  526 lines

  1. /* Definitions for values of C expressions, for GDB.
  2.    Copyright 1986, 1987, 1989, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #if !defined (VALUE_H)
  21. #define VALUE_H 1
  22.  
  23. /*
  24.  * The structure which defines the type of a value.  It should never
  25.  * be possible for a program lval value to survive over a call to the inferior
  26.  * (ie to be put into the history list or an internal variable).
  27.  */
  28. enum lval_type {
  29.   /* Not an lval.  */
  30.   not_lval,
  31.   /* In memory.  Could be a saved register.  */
  32.   lval_memory,
  33.   /* In a register.  */
  34.   lval_register,
  35.   /* In a gdb internal variable.  */
  36.   lval_internalvar,
  37.   /* Part of a gdb internal variable (structure field).  */
  38.   lval_internalvar_component,
  39.   /* In a register series in a frame not the current one, which may have been
  40.      partially saved or saved in different places (otherwise would be
  41.      lval_register or lval_memory).  */
  42.   lval_reg_frame_relative
  43. };
  44.  
  45. struct value
  46.   {
  47.     /* Type of value; either not an lval, or one of the various
  48.        different possible kinds of lval.  */
  49.     enum lval_type lval;
  50.     /* Location of value (if lval).  */
  51.     union
  52.       {
  53.     /* Address in inferior or byte of registers structure.  */
  54.     CORE_ADDR address;
  55.     /* Pointer to interrnal variable.  */
  56.     struct internalvar *internalvar;
  57.     /* Number of register.  Only used with
  58.        lval_reg_frame_relative.  */
  59.     int regnum;
  60.       } location;
  61.     /* Describes offset of a value within lval a structure in bytes.  */
  62.     int offset;    
  63.     /* Only used for bitfields; number of bits contained in them.  */
  64.     int bitsize;
  65.     /* Only used for bitfields; position of start of field.  */
  66.     int bitpos;
  67.     /* Frame value is relative to.  In practice, this address is only
  68.        used if the value is stored in several registers in other than
  69.        the current frame, and these registers have not all been saved
  70.        at the same place in memory.  This will be described in the
  71.        lval enum above as "lval_reg_frame_relative".  */
  72.     CORE_ADDR frame_addr;
  73.     /* Type of the value.  */
  74.     struct type *type;
  75.     /* Values are stored in a chain, so that they can be deleted
  76.        easily over calls to the inferior.  Values assigned to internal
  77.        variables or put into the value history are taken off this
  78.        list.  */
  79.     struct value *next;
  80.     /* If an lval is forced to repeat, a new value is created with
  81.        these fields set.  The new value is not an lval.  */
  82.     short repeated;
  83.     short repetitions;
  84.     /* Register number if the value is from a register.  Is not kept
  85.        if you take a field of a structure that is stored in a
  86.        register.  Shouldn't it be?  */
  87.     short regno;
  88.     /* If zero, contents of this value are in the contents field.
  89.        If nonzero, contents are in inferior memory at address
  90.        in the location.address field plus the offset field
  91.        (and the lval field should be lval_memory).  */
  92.     char lazy;
  93.     /* If nonzero, this is the value of a variable which does not
  94.        actually exist in the program.  */
  95.     char optimized_out;
  96.     /* Actual contents of the value.  For use of this value; setting
  97.        it uses the stuff above.  Not valid if lazy is nonzero.
  98.        Target byte-order.  We force it to be aligned properly for any
  99.        possible value.  */
  100.     union {
  101.       long contents[1];
  102.       double force_double_align;
  103. #ifdef LONG_LONG
  104.       long long force_longlong_align;
  105. #endif
  106.     } aligner;
  107.  
  108.   };
  109.  
  110. typedef struct value *value;
  111.  
  112. #define VALUE_TYPE(val) (val)->type
  113. #define VALUE_LAZY(val) (val)->lazy
  114. /* VALUE_CONTENTS and VALUE_CONTENTS_RAW both return the address of
  115.    the gdb buffer used to hold a copy of the contents of the lval.  
  116.    VALUE_CONTENTS is used when the contents of the buffer are needed --
  117.    it uses value_fetch_lazy() to load the buffer from the process being 
  118.    debugged if it hasn't already been loaded.  VALUE_CONTENTS_RAW is 
  119.    used when data is being stored into the buffer, or when it is 
  120.    certain that the contents of the buffer are valid.  */
  121. #define VALUE_CONTENTS_RAW(val) ((char *) (val)->aligner.contents)
  122. #define VALUE_CONTENTS(val) ((void)(VALUE_LAZY(val) && value_fetch_lazy(val)),\
  123.                  VALUE_CONTENTS_RAW(val))
  124. extern int
  125. value_fetch_lazy PARAMS ((value val));
  126.  
  127. #define VALUE_LVAL(val) (val)->lval
  128. #define VALUE_ADDRESS(val) (val)->location.address
  129. #define VALUE_INTERNALVAR(val) (val)->location.internalvar
  130. #define VALUE_FRAME_REGNUM(val) ((val)->location.regnum)
  131. #define VALUE_FRAME(val) ((val)->frame_addr)
  132. #define VALUE_OFFSET(val) (val)->offset
  133. #define VALUE_BITSIZE(val) (val)->bitsize
  134. #define VALUE_BITPOS(val) (val)->bitpos
  135. #define VALUE_NEXT(val) (val)->next
  136. #define VALUE_REPEATED(val) (val)->repeated
  137. #define VALUE_REPETITIONS(val) (val)->repetitions
  138. #define VALUE_REGNO(val) (val)->regno
  139. #define VALUE_OPTIMIZED_OUT(val) ((val)->optimized_out)
  140.  
  141. /* Convert a REF to the object referenced. */
  142.  
  143. #define COERCE_REF(arg)    \
  144. { if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF)            \
  145.     arg = value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg)),        \
  146.              unpack_long (VALUE_TYPE (arg),            \
  147.                       VALUE_CONTENTS (arg)));}
  148.  
  149. /* If ARG is an array, convert it to a pointer.
  150.    If ARG is an enum, convert it to an integer.
  151.    If ARG is a function, convert it to a function pointer.
  152.  
  153.    References are dereferenced.  */
  154.  
  155. #define COERCE_ARRAY(arg)    \
  156. { COERCE_REF(arg);                            \
  157.   if (VALUE_REPEATED (arg)                        \
  158.       || TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY)        \
  159.     arg = value_coerce_array (arg);                    \
  160.   if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC)                   \
  161.     arg = value_coerce_function (arg);                                  \
  162.   if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM)            \
  163.     arg = value_cast (builtin_type_unsigned_int, arg);            \
  164. }
  165.  
  166. /* If ARG is an enum, convert it to an integer.  */
  167.  
  168. #define COERCE_ENUM(arg)    \
  169. { if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_REF)            \
  170.     arg = value_ind (arg);                        \
  171.   if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM)            \
  172.     arg = value_cast (builtin_type_unsigned_int, arg);            \
  173. }
  174.  
  175. /* Internal variables (variables for convenience of use of debugger)
  176.    are recorded as a chain of these structures.  */
  177.  
  178. struct internalvar
  179. {
  180.   struct internalvar *next;
  181.   char *name;
  182.   value value;
  183. };
  184.  
  185.  
  186. #include "symtab.h"
  187. #include "gdbtypes.h"
  188. #include "expression.h"
  189.  
  190. #ifdef __STDC__
  191. struct frame_info;
  192. #endif
  193.  
  194. extern void
  195. print_address_demangle PARAMS ((CORE_ADDR, FILE *, int));
  196.  
  197. extern LONGEST
  198. value_as_long PARAMS ((value val));
  199.  
  200. extern double
  201. value_as_double PARAMS ((value val));
  202.  
  203. extern CORE_ADDR
  204. value_as_pointer PARAMS ((value val));
  205.  
  206. extern LONGEST
  207. unpack_long PARAMS ((struct type *type, char *valaddr));
  208.  
  209. extern double
  210. unpack_double PARAMS ((struct type *type, char *valaddr, int *invp));
  211.  
  212. extern CORE_ADDR
  213. unpack_pointer PARAMS ((struct type *type, char *valaddr));
  214.  
  215. extern long
  216. unpack_field_as_long PARAMS ((struct type *type, char *valaddr,
  217.                   int fieldno));
  218.  
  219. extern value
  220. value_from_longest PARAMS ((struct type *type, LONGEST num));
  221.  
  222. extern value
  223. value_from_double PARAMS ((struct type *type, double num));
  224.  
  225. extern value
  226. value_at PARAMS ((struct type *type, CORE_ADDR addr));
  227.  
  228. extern value
  229. value_at_lazy PARAMS ((struct type *type, CORE_ADDR addr));
  230.  
  231. /* FIXME:  Assumes equivalence of "struct frame_info *" and "FRAME" */
  232. extern value
  233. value_from_register PARAMS ((struct type *type, int regnum,
  234.                  struct frame_info * frame));
  235.  
  236. extern value
  237. value_of_variable PARAMS ((struct symbol *var));
  238.  
  239. extern value
  240. value_of_register PARAMS ((int regnum));
  241.  
  242. /* FIXME:  Assumes equivalence of "struct frame_info *" and "FRAME" */
  243. extern value
  244. read_var_value PARAMS ((struct symbol *var, struct frame_info *frame));
  245.  
  246. /* FIXME:  Assumes equivalence of "struct frame_info *" and "FRAME" */
  247. extern value
  248. locate_var_value PARAMS ((struct symbol *var, struct frame_info *frame));
  249.  
  250. extern value
  251. allocate_value PARAMS ((struct type *type));
  252.  
  253. extern value
  254. allocate_repeat_value PARAMS ((struct type *type, int count));
  255.  
  256. extern value
  257. value_mark PARAMS ((void));
  258.  
  259. extern void
  260. value_free_to_mark PARAMS ((value mark));
  261.  
  262. extern value
  263. value_string PARAMS ((char *ptr, int len));
  264.  
  265. extern value
  266. value_binop PARAMS ((value arg1, value arg2, enum exp_opcode op));
  267.  
  268. extern value
  269. value_add PARAMS ((value arg1, value arg2));
  270.  
  271. extern value
  272. value_sub PARAMS ((value arg1, value arg2));
  273.  
  274. extern value
  275. value_coerce_array PARAMS ((value arg1));
  276.  
  277. extern value
  278. value_coerce_function PARAMS ((value arg1));
  279.  
  280. extern value
  281. value_ind PARAMS ((value arg1));
  282.  
  283. extern value
  284. value_addr PARAMS ((value arg1));
  285.  
  286. extern value
  287. value_assign PARAMS ((value toval, value fromval));
  288.  
  289. extern value
  290. value_neg PARAMS ((value arg1));
  291.  
  292. extern value
  293. value_lognot PARAMS ((value arg1));
  294.  
  295. extern value
  296. value_struct_elt PARAMS ((value *argp, value *args, char *name,
  297.               int *static_memfuncp, char *err));
  298.  
  299. extern value
  300. value_struct_elt_for_reference PARAMS ((struct type *domain,
  301.                     int offset,
  302.                     struct type *curtype,
  303.                     char *name,
  304.                     struct type *intype));
  305.  
  306. extern value
  307. value_field PARAMS ((value arg1, int fieldno));
  308.  
  309. extern value
  310. value_primitive_field PARAMS ((value arg1, int offset, int fieldno,
  311.                    struct type *arg_type));
  312.  
  313. extern value
  314. value_cast PARAMS ((struct type *type, value arg2));
  315.  
  316. extern value
  317. value_zero PARAMS ((struct type *type, enum lval_type lv));
  318.  
  319. extern value
  320. value_repeat PARAMS ((value arg1, int count));
  321.  
  322. extern value
  323. value_subscript PARAMS ((value array, value idx));
  324.  
  325. extern value
  326. value_from_vtable_info PARAMS ((value arg, struct type *type));
  327.  
  328. extern value
  329. value_being_returned PARAMS ((struct type *valtype, 
  330.                   char retbuf[REGISTER_BYTES],
  331.                   int struct_return));
  332.  
  333. extern int
  334. using_struct_return PARAMS ((value function, CORE_ADDR funcaddr,
  335.                  struct type *value_type, int gcc_p));
  336.  
  337. extern void
  338. set_return_value PARAMS ((value val));
  339.  
  340. extern value
  341. evaluate_expression PARAMS ((struct expression *exp));
  342.  
  343. extern value
  344. evaluate_type PARAMS ((struct expression *exp));
  345.  
  346. extern value
  347. parse_and_eval PARAMS ((char *exp));
  348.  
  349. extern value
  350. parse_to_comma_and_eval PARAMS ((char **expp));
  351.  
  352. extern struct type *
  353. parse_and_eval_type PARAMS ((char *p, int length));
  354.  
  355. extern CORE_ADDR
  356. parse_and_eval_address PARAMS ((char *exp));
  357.  
  358. extern CORE_ADDR
  359. parse_and_eval_address_1 PARAMS ((char **expptr));
  360.  
  361. extern value
  362. access_value_history PARAMS ((int num));
  363.  
  364. extern value
  365. value_of_internalvar PARAMS ((struct internalvar *var));
  366.  
  367. extern void
  368. set_internalvar PARAMS ((struct internalvar *var, value val));
  369.  
  370. extern void
  371. set_internalvar_component PARAMS ((struct internalvar *var, int offset,
  372.                    int bitpos, int bitsize,
  373.                    value newvalue));
  374.  
  375. extern struct internalvar *
  376. lookup_internalvar PARAMS ((char *name));
  377.  
  378. extern int
  379. value_equal PARAMS ((value arg1, value arg2));
  380.  
  381. extern int
  382. value_less PARAMS ((value arg1, value arg2));
  383.  
  384. extern int
  385. value_zerop PARAMS ((value arg1));
  386.  
  387. /* C++ */
  388.  
  389. extern value
  390. value_of_this PARAMS ((int complain));
  391.  
  392. extern value
  393. value_x_binop PARAMS ((value arg1, value arg2, enum exp_opcode op,
  394.                enum exp_opcode otherop));
  395.  
  396. extern value
  397. value_x_unop PARAMS ((value arg1, enum exp_opcode op));
  398.  
  399. extern value
  400. value_fn_field PARAMS ((struct fn_field *f, int j));
  401.  
  402. extern value
  403. value_virtual_fn_field PARAMS ((value arg1, struct fn_field *f, int j,
  404.                 struct type *type));
  405.  
  406. extern int
  407. binop_user_defined_p PARAMS ((enum exp_opcode op, value arg1, value arg2));
  408.  
  409. extern int
  410. unop_user_defined_p PARAMS ((enum exp_opcode op, value arg1));
  411.  
  412. extern int
  413. typecmp PARAMS ((int staticp, struct type *t1[], value t2[]));
  414.  
  415. extern int
  416. destructor_name_p PARAMS ((const char *name, const struct type *type));
  417.  
  418. #define value_free(val) free ((PTR)val)
  419.  
  420. extern void
  421. free_all_values PARAMS ((void));
  422.  
  423. extern void
  424. release_value PARAMS ((value val));
  425.  
  426. extern int
  427. record_latest_value PARAMS ((value val));
  428.  
  429. extern void
  430. registers_changed PARAMS ((void));
  431.  
  432. extern void
  433. read_register_bytes PARAMS ((int regbyte, char *myaddr, int len));
  434.  
  435. extern void
  436. write_register_bytes PARAMS ((int regbyte, char *myaddr, int len));
  437.  
  438. extern void
  439. read_register_gen PARAMS ((int regno, char *myaddr));
  440.  
  441. extern CORE_ADDR
  442. read_register PARAMS ((int regno));
  443.  
  444. extern void
  445. write_register PARAMS ((int regno, int val));
  446.  
  447. extern void
  448. supply_register PARAMS ((int regno, char *val));
  449.  
  450. /* FIXME:  Assumes equivalence of "struct frame_info *" and "FRAME" */
  451. extern void
  452. get_saved_register PARAMS ((char *raw_buffer, int *optimized,
  453.                 CORE_ADDR *addrp, struct frame_info *frame,
  454.                 int regnum, enum lval_type *lval));
  455.  
  456. extern void
  457. modify_field PARAMS ((char *addr, int fieldval, int bitpos, int bitsize));
  458.  
  459. extern void
  460. type_print PARAMS ((struct type *type, char *varstring, FILE *stream,
  461.             int show));
  462.  
  463. extern void
  464. type_print_1 PARAMS ((struct type *type, char *varstring, FILE *stream,
  465.               int show, int level));
  466.  
  467. /* Possibilities for prettyprint parameters to routines which print
  468.    things.  */
  469. enum val_prettyprint {
  470.   Val_no_prettyprint = 0,
  471.   Val_prettyprint,
  472.   /* Use the default setting which the user has specified.  */
  473.   Val_pretty_default
  474.   };
  475.  
  476. extern char *
  477. baseclass_addr PARAMS ((struct type *type, int index, char *valaddr,
  478.             value *valuep, int *errp));
  479.  
  480. extern void
  481. print_floating PARAMS ((char *valaddr, struct type *type, FILE *stream));
  482.  
  483. extern int
  484. value_print PARAMS ((value val, FILE *stream, int format,
  485.              enum val_prettyprint pretty));
  486.  
  487. extern int
  488. val_print PARAMS ((struct type *type, char *valaddr, CORE_ADDR address,
  489.            FILE *stream, int format, int deref_ref,
  490.            int recurse, enum val_prettyprint pretty));
  491.  
  492. /* FIXME:  Assumes equivalence of "struct frame_info *" and "FRAME" */
  493. extern void
  494. print_variable_value PARAMS ((struct symbol *var, struct frame_info *frame,
  495.                   FILE *stream));
  496.  
  497. extern value
  498. value_arg_coerce PARAMS ((value));
  499.  
  500. extern int
  501. check_field PARAMS ((value, const char *));
  502.  
  503. extern void
  504. typedef_print PARAMS ((struct type *type, struct symbol *new, FILE *stream));
  505.  
  506. extern char *
  507. internalvar_name PARAMS ((struct internalvar *var));
  508.  
  509. extern void
  510. clear_value_history PARAMS ((void));
  511.  
  512. extern void
  513. clear_internalvars PARAMS ((void));
  514.  
  515. /* From values.c */
  516.  
  517. extern value
  518. value_copy PARAMS ((value));
  519.  
  520. /* From valops.c */
  521.  
  522. extern value
  523. call_function_by_hand PARAMS ((value, int, value *));
  524.  
  525. #endif    /* !defined (VALUE_H) */
  526.